<template>
    <fieldset>
        <legend>登录界面</legend>
        <div id="app">
            <div class="login">
                <h1>请登录</h1>
                <label for="username">用户名:</label>
                <input type="text" id="username" v-model="username">
                <br>
                <label for="password">密码:</label>
                <input type="text" v-model="password">
                <br>
                <button @click="login">登录</button>
            </div>
        </div>
        <show></show>
    </fieldset>
</template>

<script>

const loginApi = (params = {}) =>{
    return fetch('http://chst.vip/users/login',{
        method:"post",
        headers:{
            mode: "no-cors",
        },
        body:JSON.stringify(params)
    })
    .then(body => body.json())
    .catch(err => err.toString())
}


    import show from "./show.vue"
    export default {
        data(){
            return {
                    username:"",
                    password:"",
                    toDos:[
                        {
                            id:1,
                            todo:"写代码",
                            isComplete:false
                        },
                        {
                            id:2,
                            todo:"吃饭",
                            isComplete:false
                        },
                        {
                            id:3,
                            todo:"睡觉",
                            isComplete:false
                        }
                ]
            }
        },
        methods:{
            async login(){
                let res = await loginApi({username:this.username,password:this.password})
                console.log(res)
            }
        },
        components:{
            show,
        }
    }
</script>